<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/06/02
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;

/**
 * 购物车管理
 * @package app\erp\model
 */
class ErpGoodsSalecar extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_goods_salecar';

    /**
     * 添加数据
     * @param goods_id 	 int 商品id
     * @param sku_id 	 int sku_id
     * @param num 	     int 数量
     * @author shiqiang
     * @return array_out(code, message, (int)id)
     */
    public function addData($user_id, $goods_id, $sku_id, $num){
        $data['uid']      = $user_id;
        $data['goods_id'] = $goods_id;
        $data['sku_id']   = $sku_id;
        $data['num']      = $num;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	
	/**
     * 编辑数据
     * @param id 	  int    购物车id
     * @param num 	  int    数量
     * @author shiqiang
     * @return array_out(code, message, (int)id)
     */
	public function updateSkuNum($id, $num){
		$map = [];
		$map['id'] 	= $id;
		
		$data = [];
		$data['num'] = $num;

        $res = $this ->update($data, $map);

		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 编辑数据
     * @param id 	  	int    购物车id
     * @param goods_id 	int    商品id
     * @param sku_id 	int    skuid
     * @author shiqiang
     * @return array_out(code, message, (int)id)
     */
	public function updateSkuId($id, $goods_id, $sku_id){
		$map = [];
		$map['id'] 	= $id;
		
		$data = [];
		$data['goods_id'] 	= $goods_id;
		$data['sku_id'] 	= $sku_id;

        $res = $this ->update($data, $map);

		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 删除数据
     * @param int $id
     * @author dou<51779987@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
